package com.payment;

import cn.hutool.core.collection.ListUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collections;
import java.util.List;

/**
 * @author: zz
 * @Date: 2023/2/23 下午5:36
 * @Version: 1.0.0
 */
public class MybatisPlusCodeGenerator {

    public static void main(String[] args) {
        List<String> tableNames = ListUtil.of("channel_method_config");
        FastAutoGenerator.create("jdbc:mysql://localhost:3306/payment", "root", "Zz123456")
                .globalConfig(builder -> builder
                        .author("zg")
                        .enableSwagger()
                        .outputDir("/Users/zz/Downloads/tmp"))
                .packageConfig(builder -> builder
                        .parent("com.payment")
                        //模块
                        .moduleName("config")
                        .entity("entity")
                        .mapper("mapper")
                        .serviceImpl("service")
                        .controller("controller")
                        .pathInfo(Collections.singletonMap(OutputFile.xml, "/Users/zz/Downloads/tmp")))
                .strategyConfig(builder -> builder
                        //表名
                        .addInclude(tableNames))
                .strategyConfig(builder -> builder
                        .entityBuilder()
                        .enableLombok()
                        .enableRemoveIsPrefix()
                        .naming(NamingStrategy.underline_to_camel)
                        .columnNaming(NamingStrategy.underline_to_camel)
                        .idType(IdType.ASSIGN_ID)
                        .serviceBuilder()
                        .formatServiceImplFileName("%sService")
                        .mapperBuilder()
                        .mapperAnnotation(Mapper.class)
                        .formatMapperFileName("%sMapper")
                        .formatXmlFileName("%sMapper")
                        .build())
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}